<?php
defined('IN_MAIN') or exit('Invalid Access!');

function calc_next_matrix_upline_position($uid){
/*
This function calculate the next available matrix slot position for the input uid as upline
*/
	global $vars;
	$db=$vars['db'];
	
	$matrix_position = 0;
	if($user = get_user_detail_by_id($uid)){
		$matrix_position = 1;
		$t = @mysql_num_rows($r=mysql_query("select matrix_position from $db->users where matrix_upline='$uid' order by matrix_position")) or 0;
		for($i=0;$i<$t;$i++){
			$downline = mysql_fetch_assoc($r);
			if($matrix_position == $downline['matrix_position']){
				$matrix_position++;
			}
		}
	}
	
	return $matrix_position;
}
?>